package com.we823.cms.controller.front;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.we823.cms.common.WebConstants;
import com.we823.cms.common.web.FrontUtils;
import com.we823.cms.model.cms.Channel;
import com.we823.cms.repository.service.cms.ChannelService;

@Controller
public class ChannelController {
	
	private String baseUrl = WebConstants.WEB_TEMPLATE_PREFIX;

	private @Resource ChannelService channelService;
	
	@RequestMapping("channel_{id}")
	public String channel(@PathVariable("id") Integer id,HttpServletRequest request,Model model){
		Channel channelModel = channelService.findOne(id);
		if(channelModel!=null){
			if(4==channelModel.getType()){
				return "redirect:"+channelModel.getLinkurl();
			}
		}
		model.addAttribute("channel",channelModel);
		return FrontUtils.buildTemplateUrl(baseUrl, "channel");
	}
}
